<template>
	<view class="product-info">
		<view class="uni-title">仪器内部领用清单</view>
		<view class="search-box">
			<uni-search-bar :radius="25" @input="searchHandle" @cancel="cancel" cancelButton="none" placeholder="输入产品名称"></uni-search-bar>
		</view>
		
		<scroll-view scroll-y="true" class="body"  lower-threshold="150" @scrolltolower="scrollLower">
			<view class="list-box">
				<evan-radio-group v-model="activeId">
					<evan-radio class="form-row" ﻿v-for="opt in items" :key="opt.cInvCode" :label="opt.cInvCode">
						<text>{{opt.cCusName}}</text>
					</evan-radio>
				</evan-radio-group>
			</view>
		</scroll-view>
		<view class="btn-box">
			<button type="default" @click="save">确定</button>
		</view>
	</view>
</template>

<script>
	import {ajax,getUserInfo} from '@/common/common.js'
	import {Url,bpmUrl} from "@/common/config.js"
	export default {
		data() {
			return {
				items: [],
				activeId: '',
				checkedList: ['CA_1000-0101-10'],
				bpmSearch: {
					paramasMap: {},
					headersMap: {
						sysid: "bpm",
						syspwd: "pass",
						userid: ''
					},
					url: ''
				},
				loadTip: "加载中..."
			}
		},
		methods: {
			// 滑动触底
			scrollLower() {
				let sum = this.page * this.rows
				console.log('hello', sum)
				console.log('hello', this.total)
				// 当前页总数大于总个数
				if (sum > this.total) {
					this.loadTip = "找不到更多了..."
				} else {
					let params = {
						cInvCode: this.searchKey,
						page: this.page +=1
					}
					this.getItems(params)
				}
			},
			searchHandle({value: searchKey}) {
				this.items = []
				if (searchKey) {
					let params = {
						cInvCode: searchKey,
						page: 1
					}
					this.getItems(params)
				}
			},
			getItems(params = {}) {
				uni.showLoading()
				let user = uni.getStorageSync("user_info")
				this.bpmSearch.paramasMap = params
				let searchField = this.bpmSearch
				searchField.headersMap.userid = user.bpmUid
				searchField.url = bpmUrl + '/rest/appform/R_appform_CRMVR_B151'
				ajax({
					url: '/bpm/get',
					method: 'POST',
					data: searchField,
					success: res => {
						uni.hideLoading()
						let newItems = []
						if(res.data.data){
							newItems = res.data.data.rows || []
						}
						//Afan添加测试数据
						if(newItems.length==0){
							newItems = [{icon:"111",WF_OrUnid: "123",cInvCode:"10000", cCusName:"测试测试", cInvStd: "测试规格",num:"1"}]
						}
						this.items = [...this.items, ...newItems]
						this.total = res.data.total
					}
				})
			},
			save(){
				let arr = this.items.filter(item => item.cCusCode == this.cInvCode )
				if(arr.length > 0){
					this.$emit('confirm',arr[0])
				}else{
					uni.showToast({
						title:'请选择产品',
						icon:'none'
					})
				}
			}
		},
		mounted() {
			// if (options.checkedList) {
			// 	this.checkedList = JSON.parse(options.checkedList)
			// }
			// 初始化列表请求参数
			this.rows = 30
			this.page = 1
			let params = {
				page: 1
			}
			this.getItems(params)
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/css/icons.css";
	@mixin flx-row-cter {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}
	.uni-title{
		font-size: 32rpx;
		padding: 30rpx 0;
		text-align: center;
	}
	
	.evan-radio{
		padding: 10px;
		border-bottom: 1px solid #eee;
	}
	.btn-box{
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
	}
	.form-row {
		@include flx-row-cter;
		justify-content: flex-start;
		width: 100%;
	}
	.body{
		max-height: calc(100vh - 75px);
	}

</style>
